package controllers

import (
	"2212a_house/models"
	beego "github.com/beego/beego/v2/server/web"
)

type HouseController struct {
	beego.Controller
}
type JsonR struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *HouseController) List() {
	var allhouse []models.House
	err := models.DB
	if err != nil {
		c.Data["json"] = JsonR{
			Code: 0,
			Msg:  "查询失败",
			Data: nil,
		}
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = JsonR{
			Code: 200,
			Msg:  "查询成功",
			Data: allhouse,
		}
		c.ServeJSON()
	}
}
